package com.zzyl.controller;

import com.aliyun.iot20180120.models.GetDeviceStatusResponse;
import com.aliyun.iot20180120.models.QueryDevicePropertyStatusResponse;
import com.aliyun.iot20180120.models.QueryDeviceServiceDataResponse;
import com.aliyun.iot20180120.models.QueryThingModelPublishedResponse;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.dto.DeviceServiceDataPageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "物联设备管理")
@Slf4j
@RequestMapping("/iot")
public class DeviceController {
    @Autowired
    private DeviceService deviceService;

    /**
     * 查询物联网平台同步产品列表
     * @return
     */
    @PostMapping("/syncProductList")
    public ResponseResult<List<ProductVo>> getProductList(){
        log.info("查询物联网平台同步产品列表接口");
        List<ProductVo> productVos = deviceService.getProductList();
        return ResponseResult.success(productVos);
    }

    /**
     * 查询所有产品列表
     * @return
     */
    @GetMapping("/allProduct")
    public ResponseResult<List<ProductVo>> getAllProduct(){
        log.info("查询所有产品列表接口");
        List<ProductVo> productVos = deviceService.getAllProduct();
        return ResponseResult.success(productVos);
    }

    /**
     * 注册物联设备
     * @param deviceDto
     * @return
     */
    @PostMapping("/RegisterDevice")
    public ResponseResult addRegisterDevice(@RequestBody DeviceDto deviceDto){
        log.info("注册物联设备接口，入参={}",deviceDto);
        deviceService.addRegisterDevice(deviceDto);
        return ResponseResult.success();
    }

    /**
     * 分页查询设备列表
     * @param pageQueryDto
     * @return
     */
    @GetMapping("/pageQueryDevice")
    public ResponseResult<PageResponse<DeviceVo>> getDeviceList(DevicePageQueryDto pageQueryDto){
        log.info("分页查询设备列表接口，入参={}",pageQueryDto);
        PageResponse<DeviceVo> deviceVos = deviceService.getDeviceList(pageQueryDto);
        return ResponseResult.success(deviceVos);
    }

    /**
     * 查询设备详细数据
     * @param deviceDto
     * @return
     */
    @PostMapping("/QueryDeviceDetail")
    public ResponseResult<DeviceVo> getDeviceDetail(@RequestBody DeviceDto deviceDto){
        log.info("查询设备详细数据接口，入参={}",deviceDto);
        DeviceVo deviceVo = deviceService.getDeviceDetail(deviceDto);
        return ResponseResult.success(deviceVo);
    }

    /**
     * 查询指定设备的物模型运行状态
     * @param deviceDto
     * @return
     */
    @PostMapping("/QueryDevicePropertyStatus")
    public ResponseResult getDeviceStatus(@RequestBody DeviceDto deviceDto){
        log.info("查询指定设备的物模型运行状态接口，入参={}",deviceDto);
        QueryDevicePropertyStatusResponse response = deviceService.getDeviceStatus(deviceDto);
        return ResponseResult.success(response.getBody().getData());
    }

    /**
     * 查看指定产品的已发布物模型中的功能定义详情
     * @param deviceDto
     * @return
     */
    @PostMapping("/QueryThingModelPublished")
    public ResponseResult getModelPublished(@RequestBody DeviceDto deviceDto){
        log.info("查看指定产品的已发布物模型中的功能定义详情接口，入参={}",deviceDto);
        QueryThingModelPublishedResponse response = deviceService.getModelPublished(deviceDto);
        return ResponseResult.success(response.getBody().getData());
    }

    /**
     * 修改设备备注名称接口
     * @param deviceDto
     * @return
     */
    @PostMapping("/UpdateDevice")
    public ResponseResult UpdateDevice(@RequestBody DeviceDto deviceDto){
        log.info("修改设备备注名称接口，入参={}",deviceDto);
        deviceService.UpdateDevice(deviceDto);
        return ResponseResult.success();
    }

    /**
     * 删除设备
     * @param deviceDto
     * @return
     */
    @DeleteMapping("/DeleteDevice")
    public ResponseResult deleteDevice(@RequestBody DeviceDto deviceDto){
        log.info("删除设备接口，入参={}",deviceDto);
        deviceService.deleteDevice(deviceDto);
        return ResponseResult.success();
    }

    /**
     * 分页查询设备服务调用数据
     * @param pageQueryDto
     * @return
     */
    @GetMapping("/pageQueryDeviceServiceData")
    public ResponseResult getServiceDataPage(DeviceServiceDataPageQueryDto pageQueryDto){
        log.info("分页查询设备服务调用数据接口，入参={}",pageQueryDto);
        QueryDeviceServiceDataResponse response = deviceService.getServiceDataPage(pageQueryDto);
        return ResponseResult.success(response.getBody().getData());
    }
}
